//==========================================================
// 此代码由TilverNET代码生成工具自动生成，请不要修改
// 代码生成器版本号：1.2
// 作者：landy
// 联系方式：(QQ)86566178
// 创建时间：2014/6/21 10:58:22
//==========================================================

using System;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using System.Linq;
using Tilver.Data;
using Tilver.Data.DataPager;

namespace Weixin.MP.DAL.WeixinMP
{
	#region EO

	/// <summary>
	/// 请求消息日志表 《dbo.RequestMessageLog(实体类)》
	/// </summary>
	[Serializable]
	public class RequestMessageLogEO : IRowMapper<RequestMessageLogEO>
	{
		protected bool _hasOriginal = false;
		protected long _reqId;
		protected long _originalReqId;
		protected long? _msgId;
		protected string _msgType;
		protected string _toUser;
		protected string _fromUser;
		protected DateTime? _createTime;
		protected string _reqXml;
		protected DateTime? _reqTime;

		/// <summary>
		/// 主键是否有原始值（即数据库中保存的值），用于实体对象更新时
		/// </summary>
		public bool HasOriginal
		{
			get { return _hasOriginal; }
		}


		/// <summary>
		/// 日志ID 《[主键]  [bigint]   自增字段》
		/// </summary>
		public long ReqId
		{
			get { return _reqId; }
			set { _reqId = value;}
		}

		/// <summary>
		/// 日志ID 《数据库中的原始主键值副本》
		/// </summary>
		public long OriginalReqId
		{
			get { return _originalReqId; }
			set { 
				_hasOriginal = true;
				_originalReqId = value;
			}
		}

		/// <summary>
		/// 请求消息ID 《[字段]  [bigint]》
		/// </summary>
		public long? MsgId
		{
			get { return _msgId; }
			set { _msgId = value;}
		}

		/// <summary>
		/// 消息类型 《[字段]  [varchar]》
		/// </summary>
		public string MsgType
		{
			get { return _msgType; }
			set { _msgType = value;}
		}

		/// <summary>
		/// 接收用户 《[字段]  [varchar]》
		/// </summary>
		public string ToUser
		{
			get { return _toUser; }
			set { _toUser = value;}
		}

		/// <summary>
		/// 来源用户 《[字段]  [varchar]》
		/// </summary>
		public string FromUser
		{
			get { return _fromUser; }
			set { _fromUser = value;}
		}

		/// <summary>
		/// 创建时间 《[字段]  [datetime]》
		/// </summary>
		public DateTime? CreateTime
		{
			get { return _createTime; }
			set { _createTime = value;}
		}

		/// <summary>
		/// 请求文本 《[字段]  [nvarchar]》
		/// </summary>
		public string ReqXml
		{
			get { return _reqXml; }
			set { _reqXml = value;}
		}

		/// <summary>
		/// 请求时间 《[字段]  [datetime]》
		/// </summary>
		public DateTime? ReqTime
		{
			get { return _reqTime; }
			set { _reqTime = value;}
		}

		/// <summary>
		/// 默认构造函数
		/// </summary>
		public RequestMessageLogEO() 
		{
			ReqTime = DateTime.Now;
		}

		/// <summary>
		/// 自定义构造函数
		/// </summary>
		/// <param name = "reqId">日志ID</param>
		/// <param name = "msgId">请求消息ID</param>
		/// <param name = "msgType">消息类型</param>
		/// <param name = "toUser">接收用户</param>
		/// <param name = "fromUser">来源用户</param>
		/// <param name = "createTime">创建时间</param>
		/// <param name = "reqXml">请求文本</param>
		/// <param name = "reqTime">请求时间</param>
		public RequestMessageLogEO(long reqId, long? msgId, string msgType, string toUser, string fromUser, DateTime? createTime, string reqXml, DateTime? reqTime) 
		{
			_reqId = reqId;
			_msgId = msgId;
			_msgType = msgType;
			_toUser = toUser;
			_fromUser = fromUser;
			_createTime = createTime;
			_reqXml = reqXml;
			_reqTime = reqTime;
		}


		/// <summary>
		/// 将结果集映射成实体对象
		/// </summary>
		/// <param name = "reader">只进结果集流</param>
		/// <return></return>
		public RequestMessageLogEO MapRow(IDataReader reader)
		{
			var ret = new RequestMessageLogEO();
			ret.ReqId = (long)reader["ReqId"];
			ret.OriginalReqId = ret.ReqId;
			ret.MsgId = (reader["MsgId"] is DBNull) ? null : (long?)reader["MsgId"];
			ret.MsgType = (reader["MsgType"] is DBNull) ? null : (string)reader["MsgType"];
			ret.ToUser = (reader["ToUser"] is DBNull) ? null : (string)reader["ToUser"];
			ret.FromUser = (reader["FromUser"] is DBNull) ? null : (string)reader["FromUser"];
			ret.CreateTime = (reader["CreateTime"] is DBNull) ? null : (DateTime?)reader["CreateTime"];
			ret.ReqXml = (reader["ReqXml"] is DBNull) ? null : (string)reader["ReqXml"];
			ret.ReqTime = (reader["ReqTime"] is DBNull) ? null : (DateTime?)reader["ReqTime"];
			return ret;
		}

		/// <summary>
		/// 将结果集映射成实体对象，返回映射方法
		/// </summary>
		/// <return></return>
		public Func<IDataReader, RequestMessageLogEO> GetMapper()
		{
			return MapRow;
		}


	}


	#endregion
	#region MO

	/// <summary>
	/// 请求消息日志表 《dbo.RequestMessageLog(逻辑类)》
	/// </summary>
	public class RequestMessageLogMO : DbManagerBase
	{

		#region 构造函数
		/// <summary>
		/// 构造函数
		/// </summary>
		/// <param name = "routeData">路由数据</param>
		public RequestMessageLogMO(object routeData = null) : base(routeData) { }

		/// <summary>
		/// 构造函数
		/// </summary>
		/// <param name = "connectionStringName">连接字符串名称</param>
		public RequestMessageLogMO(string connectionStringName) : base(connectionStringName) { }

		#endregion

		#region 私有方法
		/// <summary>
		/// 数据库访问操作方法
		/// </summary>
		/// <param name = "sql">SQL语句</param>
		/// <return>返回数据操作对象</return>
		private DbAdoBase AdoBase(string sql)
		{
			return DataBase.CreateDbAdo(sql, CommandType.Text);
		}

		#endregion

		#region Select方法集合
		/// <summary>
		/// 按主键查询
		/// </summary>
		/// <param name = "reqId">日志ID</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public RequestMessageLogEO SelectByPK(long reqId, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			sql.AppendFormat(@"SELECT [ReqId], [MsgId], [MsgType], [ToUser], [FromUser], [CreateTime], [ReqXml], [ReqTime] FROM [dbo].[RequestMessageLog] WHERE [ReqId]=@ReqId ");
			return AdoBase(sql.ToString())
							.AddInParameter("@ReqId", reqId, DbType.Int64, 8)
							.ExecuteReader(tm).MapToSingle(new RequestMessageLogEO().GetMapper());
		}


		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "reqId">日志ID</param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<RequestMessageLogEO> SelectByReqId(long reqId, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [ReqId], [MsgId], [MsgType], [ToUser], [FromUser], [CreateTime], [ReqXml], [ReqTime] FROM [dbo].[RequestMessageLog] WHERE [ReqId]=@ReqId");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@ReqId", reqId, DbType.Int64, 8)
							.ExecuteList(new RequestMessageLogEO().GetMapper(), tm);
		}
		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "msgId">请求消息ID</param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<RequestMessageLogEO> SelectByMsgId(long? msgId, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [ReqId], [MsgId], [MsgType], [ToUser], [FromUser], [CreateTime], [ReqXml], [ReqTime] FROM [dbo].[RequestMessageLog] WHERE [MsgId]=@MsgId");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@MsgId", msgId, DbType.Int64, 8)
							.ExecuteList(new RequestMessageLogEO().GetMapper(), tm);
		}
		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "msgType">消息类型</param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<RequestMessageLogEO> SelectByMsgType(string msgType, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [ReqId], [MsgId], [MsgType], [ToUser], [FromUser], [CreateTime], [ReqXml], [ReqTime] FROM [dbo].[RequestMessageLog] WHERE [MsgType]=@MsgType");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@MsgType", msgType, DbType.AnsiString, 20)
							.ExecuteList(new RequestMessageLogEO().GetMapper(), tm);
		}
		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "toUser">接收用户</param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<RequestMessageLogEO> SelectByToUser(string toUser, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [ReqId], [MsgId], [MsgType], [ToUser], [FromUser], [CreateTime], [ReqXml], [ReqTime] FROM [dbo].[RequestMessageLog] WHERE [ToUser]=@ToUser");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@ToUser", toUser, DbType.AnsiString, 100)
							.ExecuteList(new RequestMessageLogEO().GetMapper(), tm);
		}
		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "fromUser">来源用户</param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<RequestMessageLogEO> SelectByFromUser(string fromUser, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [ReqId], [MsgId], [MsgType], [ToUser], [FromUser], [CreateTime], [ReqXml], [ReqTime] FROM [dbo].[RequestMessageLog] WHERE [FromUser]=@FromUser");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@FromUser", fromUser, DbType.AnsiString, 100)
							.ExecuteList(new RequestMessageLogEO().GetMapper(), tm);
		}
		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "createTime">创建时间</param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<RequestMessageLogEO> SelectByCreateTime(DateTime? createTime, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [ReqId], [MsgId], [MsgType], [ToUser], [FromUser], [CreateTime], [ReqXml], [ReqTime] FROM [dbo].[RequestMessageLog] WHERE [CreateTime]=@CreateTime");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@CreateTime", createTime, DbType.DateTime, 8)
							.ExecuteList(new RequestMessageLogEO().GetMapper(), tm);
		}
		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "reqXml">请求文本</param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<RequestMessageLogEO> SelectByReqXml(string reqXml, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [ReqId], [MsgId], [MsgType], [ToUser], [FromUser], [CreateTime], [ReqXml], [ReqTime] FROM [dbo].[RequestMessageLog] WHERE [ReqXml]=@ReqXml");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@ReqXml", reqXml, DbType.String, -1)
							.ExecuteList(new RequestMessageLogEO().GetMapper(), tm);
		}
		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "reqTime">请求时间</param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<RequestMessageLogEO> SelectByReqTime(DateTime? reqTime, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [ReqId], [MsgId], [MsgType], [ToUser], [FromUser], [CreateTime], [ReqXml], [ReqTime] FROM [dbo].[RequestMessageLog] WHERE [ReqTime]=@ReqTime");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@ReqTime", reqTime, DbType.DateTime, 8)
							.ExecuteList(new RequestMessageLogEO().GetMapper(), tm);
		}

		/// <summary>
		/// 按自定义条件查询
		/// </summary>
		/// <param name = "where">自定义条件,where子句</param>
		/// <param name = "top">获取行数</param>
		/// <param name = "sort">排序表达式</param>
		/// <param name = "paras">where子句中定义的参数集合</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<RequestMessageLogEO> Select(string where, int top, string sort, IEnumerable<DbParameter> paras, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [ReqId], [MsgId], [MsgType], [ToUser], [FromUser], [CreateTime], [ReqXml], [ReqTime] FROM [dbo].[RequestMessageLog] ");
			if (!string.IsNullOrEmpty(where)) format.AppendFormat(" WHERE {0} ", where);
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddParameters(paras)
							.ExecuteList(new RequestMessageLogEO().GetMapper(), tm);
		}

		/// <summary>
		/// 分页查询
		/// </summary>
		/// <param name = "where">条件表达式</param>
		/// <param name = "sort">排序表达式</param>
		/// <param name = "paras">传入参数</param>
		/// <param name = "pageSize">页大小</param>
		/// <param name = "pageIndex">页码</param>
		/// <param name = "recordCount">总记录数，由于计算总记录数影响数据库性能，只有小于或等于0的情况下才返回总记录数</param>
		/// <return>分页数据</return>
		public List<RequestMessageLogEO> SelectPager(string where, string sort, IList<DbParameter> paras, long pageSize, long pageIndex, ref long recordCount)
		{
			var sql = new StringBuilder();
			sql.AppendFormat(@"SELECT [ReqId], [MsgId], [MsgType], [ToUser], [FromUser], [CreateTime], [ReqXml], [ReqTime] FROM [dbo].[RequestMessageLog]");
			if (!string.IsNullOrEmpty(where)) sql.AppendFormat(" WHERE {0} ", where);
			if (!string.IsNullOrEmpty(sort)) sql.AppendFormat(" ORDER BY {0} ", sort);
			var pager = this.DataBase.CreatePager(sql.ToString(), pageSize, "ReqId");
			pager.AddParameters(paras);
			if (recordCount <= 0)
			{
				recordCount = pager.GetRecordCount();
			}
			return pager.GetPageData(pageIndex).MapToList(new RequestMessageLogEO().GetMapper());
		}

		#endregion

		#region Insert方法集合
		/// <summary>
		/// 插入数据，有自增列时，item中自增字段为新增值，否则，返回影响的行数
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "item">要插入的实体对象</param>
		/// <return></return>
		public int Insert(RequestMessageLogEO item, TransactionManager tm = null)
		{
			const string sql = @"INSERT INTO [dbo].[RequestMessageLog] ([MsgId], [MsgType], [ToUser], [FromUser], [CreateTime], [ReqXml], [ReqTime]) VALUES (@MsgId, @MsgType, @ToUser, @FromUser, @CreateTime, @ReqXml, @ReqTime) ;SELECT SCOPE_IDENTITY();";
			item.ReqId = long.Parse(AdoBase(sql)
												.AddInParameter("@MsgId", item.MsgId.HasValue ? (object)item.MsgId.Value : DBNull.Value, DbType.Int64, 8)
												.AddInParameter("@MsgType", item.MsgType != null ?  (object)item.MsgType : DBNull.Value, DbType.AnsiString, 20)
												.AddInParameter("@ToUser", item.ToUser != null ?  (object)item.ToUser : DBNull.Value, DbType.AnsiString, 100)
												.AddInParameter("@FromUser", item.FromUser != null ?  (object)item.FromUser : DBNull.Value, DbType.AnsiString, 100)
												.AddInParameter("@CreateTime", item.CreateTime.HasValue ? (object)item.CreateTime.Value : DBNull.Value, DbType.DateTime, 8)
												.AddInParameter("@ReqXml", item.ReqXml != null ?  (object)item.ReqXml : DBNull.Value, DbType.String, -1)
												.AddInParameter("@ReqTime", item.ReqTime.HasValue ? (object)item.ReqTime.Value : DBNull.Value, DbType.DateTime, 8)
												.ExecuteScalar(tm).ToString());
			return 1;
		}
		#endregion

		#region Update方法集合
		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "item">要更新的实体对象</param>
		/// <param name = "tm">事务管理对象</param>
		/// <return></return>
		public int Update(RequestMessageLogEO item, TransactionManager tm = null)
		{
			const string sql = @"UPDATE [dbo].[RequestMessageLog] SET [MsgId]=@MsgId, [MsgType]=@MsgType, [ToUser]=@ToUser, [FromUser]=@FromUser, [CreateTime]=@CreateTime, [ReqXml]=@ReqXml, [ReqTime]=@ReqTime WHERE [ReqId]=@OriginalReqId";
			return AdoBase(sql)
							.AddInParameter("@OriginalReqId", (item.HasOriginal) ? item.OriginalReqId : item.ReqId, DbType.Int64, 8)
							.AddInParameter("@MsgId", item.MsgId.HasValue ? (object)item.MsgId.Value : DBNull.Value, DbType.Int64, 8)
							.AddInParameter("@MsgType", item.MsgType != null ?  (object)item.MsgType : DBNull.Value, DbType.AnsiString, 20)
							.AddInParameter("@ToUser", item.ToUser != null ?  (object)item.ToUser : DBNull.Value, DbType.AnsiString, 100)
							.AddInParameter("@FromUser", item.FromUser != null ?  (object)item.FromUser : DBNull.Value, DbType.AnsiString, 100)
							.AddInParameter("@CreateTime", item.CreateTime.HasValue ? (object)item.CreateTime.Value : DBNull.Value, DbType.DateTime, 8)
							.AddInParameter("@ReqXml", item.ReqXml != null ?  (object)item.ReqXml : DBNull.Value, DbType.String, -1)
							.AddInParameter("@ReqTime", item.ReqTime.HasValue ? (object)item.ReqTime.Value : DBNull.Value, DbType.DateTime, 8)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "reqId">日志ID</param>
		/// <param name = "msgId">请求消息ID</param>
		/// <return></return>
		public virtual int UpdateMsgId(long reqId, long? msgId)
		{
			return UpdateMsgId(reqId, msgId, null);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "tm">事务管理对象</param>
		/// <param name = "reqId">日志ID</param>
		/// <param name = "msgId">请求消息ID</param>
		/// <return></return>
		public virtual int UpdateMsgId(long reqId, long? msgId, TransactionManager tm = null)
		{
			const string sql = @"UPDATE [dbo].[RequestMessageLog] SET [MsgId]=@MsgId  WHERE [ReqId]=@ReqId";
			return AdoBase(sql)
							.AddInParameter("@MsgId", msgId.HasValue ? (object)msgId.Value : DBNull.Value, DbType.Int64, 8)
							.AddInParameter("@ReqId", reqId, DbType.Int64, 8)
							.ExecuteNonQuery(tm);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "reqId">日志ID</param>
		/// <param name = "msgType">消息类型</param>
		/// <return></return>
		public virtual int UpdateMsgType(long reqId, string msgType)
		{
			return UpdateMsgType(reqId, msgType, null);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "tm">事务管理对象</param>
		/// <param name = "reqId">日志ID</param>
		/// <param name = "msgType">消息类型</param>
		/// <return></return>
		public virtual int UpdateMsgType(long reqId, string msgType, TransactionManager tm = null)
		{
			const string sql = @"UPDATE [dbo].[RequestMessageLog] SET [MsgType]=@MsgType  WHERE [ReqId]=@ReqId";
			return AdoBase(sql)
							.AddInParameter("@MsgType", msgType != null ?  (object)msgType : DBNull.Value, DbType.AnsiString, 20)
							.AddInParameter("@ReqId", reqId, DbType.Int64, 8)
							.ExecuteNonQuery(tm);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "reqId">日志ID</param>
		/// <param name = "toUser">接收用户</param>
		/// <return></return>
		public virtual int UpdateToUser(long reqId, string toUser)
		{
			return UpdateToUser(reqId, toUser, null);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "tm">事务管理对象</param>
		/// <param name = "reqId">日志ID</param>
		/// <param name = "toUser">接收用户</param>
		/// <return></return>
		public virtual int UpdateToUser(long reqId, string toUser, TransactionManager tm = null)
		{
			const string sql = @"UPDATE [dbo].[RequestMessageLog] SET [ToUser]=@ToUser  WHERE [ReqId]=@ReqId";
			return AdoBase(sql)
							.AddInParameter("@ToUser", toUser != null ?  (object)toUser : DBNull.Value, DbType.AnsiString, 100)
							.AddInParameter("@ReqId", reqId, DbType.Int64, 8)
							.ExecuteNonQuery(tm);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "reqId">日志ID</param>
		/// <param name = "fromUser">来源用户</param>
		/// <return></return>
		public virtual int UpdateFromUser(long reqId, string fromUser)
		{
			return UpdateFromUser(reqId, fromUser, null);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "tm">事务管理对象</param>
		/// <param name = "reqId">日志ID</param>
		/// <param name = "fromUser">来源用户</param>
		/// <return></return>
		public virtual int UpdateFromUser(long reqId, string fromUser, TransactionManager tm = null)
		{
			const string sql = @"UPDATE [dbo].[RequestMessageLog] SET [FromUser]=@FromUser  WHERE [ReqId]=@ReqId";
			return AdoBase(sql)
							.AddInParameter("@FromUser", fromUser != null ?  (object)fromUser : DBNull.Value, DbType.AnsiString, 100)
							.AddInParameter("@ReqId", reqId, DbType.Int64, 8)
							.ExecuteNonQuery(tm);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "reqId">日志ID</param>
		/// <param name = "createTime">创建时间</param>
		/// <return></return>
		public virtual int UpdateCreateTime(long reqId, DateTime? createTime)
		{
			return UpdateCreateTime(reqId, createTime, null);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "tm">事务管理对象</param>
		/// <param name = "reqId">日志ID</param>
		/// <param name = "createTime">创建时间</param>
		/// <return></return>
		public virtual int UpdateCreateTime(long reqId, DateTime? createTime, TransactionManager tm = null)
		{
			const string sql = @"UPDATE [dbo].[RequestMessageLog] SET [CreateTime]=@CreateTime  WHERE [ReqId]=@ReqId";
			return AdoBase(sql)
							.AddInParameter("@CreateTime", createTime.HasValue ? (object)createTime.Value : DBNull.Value, DbType.DateTime, 8)
							.AddInParameter("@ReqId", reqId, DbType.Int64, 8)
							.ExecuteNonQuery(tm);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "reqId">日志ID</param>
		/// <param name = "reqXml">请求文本</param>
		/// <return></return>
		public virtual int UpdateReqXml(long reqId, string reqXml)
		{
			return UpdateReqXml(reqId, reqXml, null);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "tm">事务管理对象</param>
		/// <param name = "reqId">日志ID</param>
		/// <param name = "reqXml">请求文本</param>
		/// <return></return>
		public virtual int UpdateReqXml(long reqId, string reqXml, TransactionManager tm = null)
		{
			const string sql = @"UPDATE [dbo].[RequestMessageLog] SET [ReqXml]=@ReqXml  WHERE [ReqId]=@ReqId";
			return AdoBase(sql)
							.AddInParameter("@ReqXml", reqXml != null ?  (object)reqXml : DBNull.Value, DbType.String, -1)
							.AddInParameter("@ReqId", reqId, DbType.Int64, 8)
							.ExecuteNonQuery(tm);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "reqId">日志ID</param>
		/// <param name = "reqTime">请求时间</param>
		/// <return></return>
		public virtual int UpdateReqTime(long reqId, DateTime? reqTime)
		{
			return UpdateReqTime(reqId, reqTime, null);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "tm">事务管理对象</param>
		/// <param name = "reqId">日志ID</param>
		/// <param name = "reqTime">请求时间</param>
		/// <return></return>
		public virtual int UpdateReqTime(long reqId, DateTime? reqTime, TransactionManager tm = null)
		{
			const string sql = @"UPDATE [dbo].[RequestMessageLog] SET [ReqTime]=@ReqTime  WHERE [ReqId]=@ReqId";
			return AdoBase(sql)
							.AddInParameter("@ReqTime", reqTime.HasValue ? (object)reqTime.Value : DBNull.Value, DbType.DateTime, 8)
							.AddInParameter("@ReqId", reqId, DbType.Int64, 8)
							.ExecuteNonQuery(tm);
		}

		/// <summary>
		/// 按自定义条件更新数据
		/// </summary>
		/// <param name = "set">更新列</param>
		/// <param name = "where">更新条件</param>
		/// <param name = "paras">参数集合</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public int Update(string set, string where, IEnumerable<DbParameter> paras, TransactionManager tm = null)
		{
			if (string.IsNullOrEmpty(set)) throw new ArgumentNullException("set");
			var sql = string.Format(@"UPDATE [dbo].[RequestMessageLog] SET {0} {1}", set, (string.IsNullOrEmpty(where) ? string.Empty : " WHERE " + where));
			return AdoBase(sql)
							.AddParameters(paras)
							.ExecuteNonQuery(tm);
		}
		#endregion

		#region Delete方法集合
		/// <summary>
		/// 按主键删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "reqId">日志ID</param>
		public int DeleteByPK(long reqId, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[RequestMessageLog] WHERE [ReqId]=@ReqId";
			return AdoBase(sql)
							.AddInParameter("@ReqId", reqId, DbType.Int64, 8)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 按字段删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "msgId">请求消息ID</param>
		public int DeleteByMsgId(long? msgId, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[RequestMessageLog] WHERE [MsgId]=@MsgId";
			return AdoBase(sql)
							.AddInParameter("@MsgId", msgId.HasValue ? (object)msgId.Value : DBNull.Value, DbType.Int64, 8)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 按字段删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "msgType">消息类型</param>
		public int DeleteByMsgType(string msgType, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[RequestMessageLog] WHERE [MsgType]=@MsgType";
			return AdoBase(sql)
							.AddInParameter("@MsgType", msgType != null ?  (object)msgType : DBNull.Value, DbType.AnsiString, 20)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 按字段删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "toUser">接收用户</param>
		public int DeleteByToUser(string toUser, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[RequestMessageLog] WHERE [ToUser]=@ToUser";
			return AdoBase(sql)
							.AddInParameter("@ToUser", toUser != null ?  (object)toUser : DBNull.Value, DbType.AnsiString, 100)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 按字段删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "fromUser">来源用户</param>
		public int DeleteByFromUser(string fromUser, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[RequestMessageLog] WHERE [FromUser]=@FromUser";
			return AdoBase(sql)
							.AddInParameter("@FromUser", fromUser != null ?  (object)fromUser : DBNull.Value, DbType.AnsiString, 100)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 按字段删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "createTime">创建时间</param>
		public int DeleteByCreateTime(DateTime? createTime, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[RequestMessageLog] WHERE [CreateTime]=@CreateTime";
			return AdoBase(sql)
							.AddInParameter("@CreateTime", createTime.HasValue ? (object)createTime.Value : DBNull.Value, DbType.DateTime, 8)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 按字段删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "reqXml">请求文本</param>
		public int DeleteByReqXml(string reqXml, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[RequestMessageLog] WHERE [ReqXml]=@ReqXml";
			return AdoBase(sql)
							.AddInParameter("@ReqXml", reqXml != null ?  (object)reqXml : DBNull.Value, DbType.String, -1)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 按字段删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "reqTime">请求时间</param>
		public int DeleteByReqTime(DateTime? reqTime, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[RequestMessageLog] WHERE [ReqTime]=@ReqTime";
			return AdoBase(sql)
							.AddInParameter("@ReqTime", reqTime.HasValue ? (object)reqTime.Value : DBNull.Value, DbType.DateTime, 8)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 删除指定条件的记录
		/// </summary>
		/// <param name = "whereClause">自定义删除条件，where子句。如：id=1 and name='aaa'</param>
		/// <param name = "paras">where子句中定义的参数集合</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public int Delete(string whereClause, IEnumerable<DbParameter> paras, TransactionManager tm = null)
		{
			var sql = string.Format(@"DELETE FROM [dbo].[RequestMessageLog] {0}", (string.IsNullOrEmpty(whereClause) ? string.Empty : " WHERE " + whereClause));
			return AdoBase(sql)
							.AddParameters(paras)
							.ExecuteNonQuery(tm);
		}
		#endregion

		#region  自定义方法集合
		#endregion

	}


	#endregion
}
